/**
 * @param {string} s
 * @return {string}
 */
var maskPII = function (s) {
  let res = ''
  if (s.indexOf('@') > -1) {
    let [info, domain] = s.toLowerCase().split('@')
    res = info[0] + '*'.repeat(5) + info[info.length - 1] + '@' + domain
  } else {
    let str = '',
      temp = '***-***-'
    for (const c of s) {
      if (c >= 0 && c <= 9 && c != ' ') {
        str += c
      }
    }
    if (str.length == 10) {
      res = temp + str.slice(6, 10)
    } else if (str.length == 11) {
      res = '+*-' + temp + str.slice(7, 11)
    } else if (str.length == 12) {
      res = '+**-' + temp + str.slice(8, 12)
    } else {
      res = '+***-' + temp + str.slice(9, 13)
    }
  }

  return res
}

maskPII('(3906)2 07143 711')
